//
//  UIWindow+Extension.m
//  ChaosWeiBo
//
//  Created by admin on 16/8/1.
//  Copyright © 2016年 Chaos. All rights reserved.
//

#import "UIWindow+Extension.h"
#import "MATabBarViewController.h"
#import "ChaosNewFeatureController.h"

@implementation UIWindow (Extension)
/// 用来切换根控制器方法
- (void)switchRootViewController
{
    // 1.从沙盒中获取旧的版本号
    NSString *oldVersion = [[NSUserDefaults standardUserDefaults] objectForKey:@"CFBundleVersion"];
    // 2.获取新的版本号
    NSString *newVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleVersion"];
    if ([oldVersion isEqualToString:newVersion]) { // 版本号相同,不显示新界面
        
        MATabBarViewController *tabBarVC = [[MATabBarViewController alloc] init];
        self.rootViewController = tabBarVC;
    } else { // 版本号不相同,显示新特性,并存储版本号到沙盒
        
        ChaosNewFeatureController *newFeatureVC = [[ChaosNewFeatureController alloc] init];
        self.rootViewController = newFeatureVC;
        // 3.将新的版本号存储
        [[NSUserDefaults standardUserDefaults] setObject:newVersion forKey:@"CFBundleVersion"];
    }
}
@end
